<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
class Imessage_model extends Model
{
	function Imessage_model()
	{
		parent::Model();
	}
	function add_record()
	{
		$data=array(
			'title'=>$this->input->post("title"),
			'catalog_id'=>$this->input->post("catalog_id"),
			'seqorder'=>$this->input->post("seqorder"),
			'user_id'=>$this->input->post("user_id")
		);
		$this->db->insert("imessage",$data);
		return TRUE;
	}
	function get_records()
	{
		$this->db->order_by('seqorder','desc');
		$this->db->order_by('id','desc');
		return $this->db->get("imessage");
	}
	
	function get_record($id)
	{
		$query=$this->db->get_where("imessage",array('id'=>$id));
		if($query->num_rows()>0)
		{
			return $query->row_array();
		}
	}
	
	function sort_record()
	{
		$rd_id=$this->input->post("rd_id");
		if(!is_array($rd_id))
		{
			return FALSE;
		}
		foreach($rd_id as $row)
		{
			$sort_value=$this->input->post("sort".$row)?(int)$this->input->post("sort".$row):0;
			$this->db->update("imessage",array('seqorder'=>$sort_value),array('id'=>$row));
		}
		return TRUE;
	}
	
	function save_record()
	{
		$rd_id=$this->input->post("rd_id");
		$data=array(
			'title'=>$this->input->post("title"),
			'catalog_id'=>$this->input->post("catalog_id"),
			'seqorder'=>$this->input->post("seqorder"),
			'user_id'=>$this->input->post("user_id")
		);
		$this->db->update("imessage",$data,array('id'=>$rd_id));
		return TRUE;
	}
	
	function del_record()
	{
		$rd_id=$this->input->post("rd_id");
		if(!is_array($rd_id))
		{
			return FALSE;
		}
		$this->db->where_in("id",$rd_id);
		$this->db->delete("imessage");
		if($this->db->affected_rows())
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_catalog_list()
	{
		$query=$this->db->get("imessage_catalog");
		return $query->result();
	}
}
?>